/*
 * @(#)JaccardSimilarity.java	1.0 01/01/05
 *
 * Copyright 2007 Fabio Gasparetti. All rights reserved.
 */
package org.tabularium.text;

import org.tabularium.text.analysis.*;

/**
 * Draws text similarities according to the Jaccard measure.
 * 
 * @author  Fabio Gasparetti
 * @version 1.0, 01/01/05
 */
public class JaccardSimilarity implements TextSimilarity {
	protected Analyzer analyzer;

	public JaccardSimilarity(Analyzer analyzer) {
		this.analyzer = analyzer;
	}

	/*
	 * (non-Javadoc)
	 * @see org.tabularium.text.TextSimilarity#similarity(java.lang.String, java.lang.String)
	 */
	public double similarity(String text1, String text2) {
		text1 = text1.toLowerCase();
		text2 = text2.toLowerCase();
		TermWeightVector v1 = TermWeightVector
				.build(TermWeightVector.tokenize(text1));
		TermWeightVector v2 = TermWeightVector
				.build(TermWeightVector.tokenize(text2));
		return this.similarity(v1, v2);
	}

	/*
	 * (non-Javadoc)
	 * @see org.tabularium.text.TextSimilarity#similarity(org.tabularium.text.TermFreqVector, org.tabularium.text.TermFreqVector)
	 */
	public double similarity(TermWeightVector v1, TermWeightVector v2) {
		return v1.jaccard(v2);
	}
}
